package com.design_patterns.chain_of_responsibility;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: 李德才
 * @description:
 * @create: 2020-08-25 22:39
 **/
public class Main {

    public static void main(String[] args) {
        String str = " 干坏事 <script> location.href='www.xxxx.com' </script> 说坏话：工作 996 ";
        Msg msg = new Msg();
        msg.setMsg(str);

        List<Filter> filterList = new ArrayList<>();
        filterList.add(new HtmlFilter());
        filterList.add(new SensitiveFilter());
        filterList.forEach(filter -> {
            filter.doFilter(msg);
        });

        System.err.println(msg.getMsg());
    }


    interface Filter {
        void doFilter(Msg m);
    }

    static class HtmlFilter implements Filter {

        @Override
        public void doFilter(Msg m) {
            m.setMsg(m.getMsg().replace("<", "[").replace(">", "]"));
        }
    }

    static class SensitiveFilter implements Filter {

        @Override
        public void doFilter(Msg m) {
            m.setMsg(m.getMsg().replace("996", "955"));
        }
    }


    static class Msg {
        private String msg;

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }


        @Override
        public String toString() {
            return "Msg{" +
                    "msg='" + msg + '\'' +
                    '}';
        }
    }


}
